function add(a: number = 10, b?: number): number {
    console.log('b', b)
    return a + 1
}
console.log(add(1, 2))

// 定义this
interface Obj {
    user: number[],
    add: (this: Obj, num: number) => void
}
let obj: Obj = {
    user: [1, 2, 3, 4],
    add(this: Obj, num: number) {
        this.user.push(num)
        console.log(this.user)
    }
}
obj.add(5)

// 函数重载
let user: number[] = [1, 2, 3]
function findNum(add: number[]): number[]    //传入数组就加入
function findNum(id: number): number[]   //返回id对应的
function findNum(): number[]     //没有传入返回所有
function findNum(id?: number | number[]): number[] {
    if (typeof id === 'number') {
        return user.filter(item => item === id)
    } else if (Array.isArray(id)) {
        user.push(...id)
        return user
    } else {
        return user
    }
}
console.log('---------------')
console.log(findNum([4,5,6]))
console.log(findNum())
console.log(findNum(1))


